import {
	URL
} from '@/config/config.js'

const post = (method, data, callback, timout, fails) => {
	let header = {
		// 'content-type': 'application/form-data;charset=UTF-8'
		// 'content-type': 'application/x-www-form-urlencoded',
		// 'connection':'keep-alive'
	}
	let timsout = 60000
	if (timout) {
		timsout = timout
	}
	let token = uni.getStorageSync('token')
	// if (!token) {
	// 	uni.navigateTo({
	// 		url: '/pages/login/login'
	// 	})
	// } else {
	header["token"] = token
	// }
	// console.log(data,'-------------------data---');
	uni.request({
		url: URL + method,
		method: 'POST',
		data,
		header,
		timeout: timsout,
		success: (res) => {
			console.log(res,'-----------------------');
			callback(res)
		},
		fail: (err) => {
			fails(err)
		}
	})
}
// get 请求
const get = (method, data, callback) => {
	let header = {
		// 'content-type': 'application/form-data;charset=UTF-8'
	}
	// if (headertoke.indexOf(method) > -1) {
	let token = uni.getStorageSync('token')
	// 	if (!token) {
	// 		uni.navigateTo({
	// 			url: '/pages/logouser/logouser.vue'
	// 		})
	// 	} else {
	header["token"] = token
	// }
	// }
	uni.request({
		url: URL + method,
		method: 'GET',
		data,
		header,
		success: (res) => {
			console.log(res)
			callback(res)
		},
		fail: (err) => {
			console.log(err);
		}
	})
}
// 图片上传
export const uploadImg = function upload(path, callback) {
	let header = {

	}
	// if (headertoke.indexOf('/api/uploadimage') > -1) {
	let token = uni.getStorageSync('token')
	// if (!token) {
	// 	uni.navigateTo({
	// 		url: "/pages/logouser/logouser.vue"
	// 	})
	// } else {
	header["token"] = token
	// }
	// }
	uni.uploadFile({
		url: URL + '/api/common/upload',
		name: 'file',
		filePath: path,
		formData: {
			// type:1
		},
		header,
		success: (res) => {
			let result = JSON.parse(res.data)
			callback(result)
		}
	})
}

// 首页检测是否有订单 /api/User/is_havemychanorder
export const orderList = (data, callback) => post('/api/User/is_havemychanorder', data, callback)
// 首页检测是否是我值班 /api/User/Whether_on_duty
export const myworktime = (data, callback) => post('/api/User/Whether_on_duty', data, callback)
///转运单详情 api/Origbill/origdatelis
export const orderlist1 = (data, callback) => post('/api/Origbill/origdatelis', data, callback)
// 转运携带机械列表 /api/goods/zy_pickCollectionlst
export const jixielist = (data, callback) => post('/api/goods/zy_pickCollectionlst', data, callback)
// 首页获取公告 /api/Center/noticelst
export const gonggao = (data, callback) => get('/api/Center/noticelst', data, callback)
//通知 /api/center/getminemsg
export const tell = (data, callback) => get('/api/center/getminemsg', data, callback)
//客服 /api/index/customer
export const call = (data, callback) => post('/api/index/customer', data, callback)
//协议 /api/center/getjicsite
export const xieyi = (data, callback) => get('/api/center/getjicsite', data, callback)
//货物确认完毕准备出发  /api/order/Confirmdeparture
export const goto = (data, callback) => post('/api/order/Confirmdeparture', data, callback)
// 确认接到病人返回医院 /api/order/returnto_hospital
export const goback = (data, callback) => post('/api/order/returnto_hospital', data, callback)
//到达医院  /api/order/arriveatthe_hospital
export const gobackhes = (data, callback) => post('/api/order/arriveatthe_hospital', data, callback)
// 转运中订单详情  /api/Origbill/origbilllist
export const zhuanyunlist = (data, callback) => post('/api/Origbill/origbilllist', data, callback)
//转运订单详情 /api/Origbill/origdatelis
export const zhuanyunorderlist = (data, callback) => post('/api/Origbill/origdatelis', data, callback)
// 实名认证 /api/User/authuserinfo
export const truename = (data, callback) => post('/api/User/authuserinfo', data, callback)
// 上传图片  /api/common/upload
export const uplodeimg = (data, callback) => post('/api/common/upload', data, callback)
// 点击确定关闭弹窗 /api/User/up_ogillchanorder
export const closetanchang = (data, callback) => post('/api/User/up_ogillchanorder', data, callback)
